﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace syc.Sale.Report
{
    public partial class 年辅料采购合同执行表 : System.Web.UI.Page
    {
  
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // Button_Query_Click(null, null);

                this.Year.SelectedValue = DateTime.Today.Year.ToString();
                
            }
        }
        //设置表头
        protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
        {

           if (e.Row.RowType == DataControlRowType.Header)             
            {                
                    //第一行表头
                    TableCellCollection tcHeader = e.Row.Cells;
                    tcHeader.Clear();
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[0].Attributes.Add("rowspan", "2"); //跨2Row
                    tcHeader[0].Text = "辅料名称";                   
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[1].Attributes.Add("rowspan", "2"); //跨2Row
                    tcHeader[1].Text = "规格";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[2].Attributes.Add("rowspan", "2"); //跨2Row
                    tcHeader[2].Text = "计量单位";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[3].Attributes.Add("colspan", "2"); //跨3Col
                    tcHeader[3].Text = "第一季度";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[4].Attributes.Add("colspan", "2"); //跨3Col
                    tcHeader[4].Text = "第二季度";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[5].Attributes.Add("colspan", "2"); //跨3Col
                    tcHeader[5].Text = "第三季度";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[6].Attributes.Add("colspan", "2"); //跨3Col
                    tcHeader[6].Text = "第四季度";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[7].Attributes.Add("rowspan", "2"); //跨2Row
                    tcHeader[7].Text = "年合同量</th></tr><tr>"; 
                  

                    //第二行表头
                    tcHeader.Add(new TableHeaderCell());                  
                    tcHeader[8].Attributes.Add("colspan", "1"); 
                    tcHeader[8].Text = "数量";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[9].Attributes.Add("colspan", "1"); 
                    tcHeader[9].Text = "单价";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[10].Attributes.Add("colspan", "1");
                    tcHeader[10].Text = "数量";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[11].Attributes.Add("colspan", "1");
                    tcHeader[11].Text = "单价";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[12].Attributes.Add("colspan", "1");
                    tcHeader[12].Text = "数量";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[13].Attributes.Add("colspan", "1");
                    tcHeader[13].Text = "单价";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[14].Attributes.Add("colspan", "1");
                    tcHeader[14].Text = "数量";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[15].Attributes.Add("colspan", "1");
                    tcHeader[15].Text = "单价</th></tr><tr>";
              
            }
        }
        protected void Button_Query_Click(object sender, EventArgs e)
        {
           
            string sql = @"select distinct 品名,规格,单位
,dbo.季度合同量(品名,规格,*年度,1) as 一季度合同数量
,dbo.季度单价(品名,规格,*年度,1) as 一季度单价
,dbo.季度合同量(品名,规格,*年度,2) as 二季度合同数量
,dbo.季度单价(品名,规格,*年度,2) as 二季度单价
,dbo.季度合同量(品名,规格,*年度,3) as 三季度合同数量
,dbo.季度单价(品名,规格,*年度,3) as 三季度单价
,dbo.季度合同量(品名,规格,*年度,4) as 四季度合同数量
,dbo.季度单价(品名,规格,*年度,4) as 四季度单价
,(convert(int,(isnull(dbo.季度合同量(品名,规格,*年度,1),0)))+convert(int,(isnull(dbo.季度合同量(品名,规格,*年度,2),0)))+convert(int,(isnull(dbo.季度合同量(品名,规格,*年度,3),0)))+convert(int,(isnull(dbo.季度合同量(品名,规格,*年度,4),0)))) as 年合同量 from 材料 left join 辅料采购合同 on 辅料采购合同.辅料ID=材料.ID
where 品名!='其它'";
            sql=sql.Replace("*年度", this.Year.SelectedValue);
            this.SqlDataSource1.SelectCommand = sql;
            this.GridView1.DataBind();
            
        }

        protected void Button1_Click(object sender, EventArgs e)
        {

        }
    }
}
